﻿using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.Mvvm.Messaging;
using MyWpfFramework.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyWpfFramework.Pages
{
    /// <summary>
    /// uc_page2.xaml 的交互逻辑
    /// </summary>
    public partial class GridViewPage : UserControl
    {
        public GridViewPage()
        {
            InitializeComponent();

        }

        private void DoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid dataGrid = sender as DataGrid;
            DataGridRow row = FindAncestor<DataGridRow>(e.OriginalSource as DependencyObject);
            if (row != null && row.Item != null)
            {
                // 假设你的数据项是YourDataType类型
                DemoDataModel dataItem = row.Item as DemoDataModel;
                WeakReferenceMessenger.Default.Send(new ValueChangedMessage<DemoDataModel>(dataItem),"1");
            }
        }

        // 辅助方法，用于查找事件源的祖先
        public static T FindAncestor<T>(DependencyObject obj) where T : DependencyObject
        {
            do
            {
                if (obj != null && obj is T)
                {
                    return (T)obj;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
            while (obj != null);
            return null;
        }

       
    }
}
